package com.ruoyi.service.purchase.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.domain.purchase.MesPurchaseReceiptItem;
import com.ruoyi.mapper.purchase.MesPurchaseReceiptItemMapper;
import com.ruoyi.service.purchase.IMesPurchaseReceiptItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 采购入库明细Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@Service
public class MesPurchaseReceiptItemServiceImpl implements IMesPurchaseReceiptItemService {
    @Autowired
    private MesPurchaseReceiptItemMapper mesPurchaseReceiptItemMapper;

    /**
     * 查询采购入库明细
     * 
     * @param itemId 采购入库明细主键
     * @return 采购入库明细
     */
    @Override
    public MesPurchaseReceiptItem selectMesPurchaseReceiptItemByItemId(Long itemId) {
        return mesPurchaseReceiptItemMapper.selectMesPurchaseReceiptItemByItemId(itemId);
    }

    /**
     * 查询采购入库明细列表
     * 
     * @param mesPurchaseReceiptItem 采购入库明细
     * @return 采购入库明细
     */
    @Override
    public List<MesPurchaseReceiptItem> selectMesPurchaseReceiptItemList(
            MesPurchaseReceiptItem mesPurchaseReceiptItem) {
        return mesPurchaseReceiptItemMapper.selectMesPurchaseReceiptItemList(mesPurchaseReceiptItem);
    }

    /**
     * 新增采购入库明细
     * 
     * @param mesPurchaseReceiptItem 采购入库明细
     * @return 结果
     */
    @Override
    public int insertMesPurchaseReceiptItem(MesPurchaseReceiptItem mesPurchaseReceiptItem) {
        mesPurchaseReceiptItem.setCreateTime(DateUtils.getNowDate());
        mesPurchaseReceiptItem.setCreateBy(SecurityUtils.getUsername());
        return mesPurchaseReceiptItemMapper.insertMesPurchaseReceiptItem(mesPurchaseReceiptItem);
    }

    /**
     * 修改采购入库明细
     * 
     * @param mesPurchaseReceiptItem 采购入库明细
     * @return 结果
     */
    @Override
    public int updateMesPurchaseReceiptItem(MesPurchaseReceiptItem mesPurchaseReceiptItem) {
        mesPurchaseReceiptItem.setUpdateTime(DateUtils.getNowDate());
        mesPurchaseReceiptItem.setUpdateBy(SecurityUtils.getUsername());
        return mesPurchaseReceiptItemMapper.updateMesPurchaseReceiptItem(mesPurchaseReceiptItem);
    }

    /**
     * 批量删除采购入库明细
     * 
     * @param itemIds 需要删除的采购入库明细主键
     * @return 结果
     */
    @Override
    public int deleteMesPurchaseReceiptItemByItemIds(Long[] itemIds) {
        return mesPurchaseReceiptItemMapper.deleteMesPurchaseReceiptItemByItemIds(itemIds);
    }

    /**
     * 删除采购入库明细信息
     * 
     * @param itemId 采购入库明细主键
     * @return 结果
     */
    @Override
    public int deleteMesPurchaseReceiptItemByItemId(Long itemId) {
        return mesPurchaseReceiptItemMapper.deleteMesPurchaseReceiptItemByItemId(itemId);
    }

    /**
     * 根据入库单ID查询明细列表
     * 
     * @param receiptId 入库单ID
     * @return 明细列表
     */
    @Override
    public List<MesPurchaseReceiptItem> selectItemListByReceiptId(Long receiptId) {
        return mesPurchaseReceiptItemMapper.selectItemListByReceiptId(receiptId);
    }

    /**
     * 根据物料编码查询入库明细
     * 
     * @param materialCode 物料编码
     * @return 明细列表
     */
    @Override
    public List<MesPurchaseReceiptItem> selectItemListByMaterialCode(String materialCode) {
        return mesPurchaseReceiptItemMapper.selectItemListByMaterialCode(materialCode);
    }

    /**
     * 根据批次号查询入库明细
     * 
     * @param batchCode 批次号
     * @return 明细列表
     */
    @Override
    public List<MesPurchaseReceiptItem> selectItemListByBatchCode(String batchCode) {
        return mesPurchaseReceiptItemMapper.selectItemListByBatchCode(batchCode);
    }
}